package com.triones.ljr.controller.api;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.ljr.entity.dto.HandleAppDO;
import com.triones.ljr.entity.vo.CustomHandleAppVO;
import com.triones.ljr.entity.vo.HandleAppVO;
import com.triones.ljr.entity.vo.HandleCategorizeVO;
import com.triones.ljr.service.HandleAppService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * api - 我要办事
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/handleApp")
public class ApiHandleAppController extends BaseController {

    private final HandleAppService handleAppService;

    /**
     * 获取分类列表
     */
    @SaIgnore
    @GetMapping("/categorize/pageList")
    public R<List<HandleCategorizeVO>> getCategorizePageList(String keyword) {
        return R.ok(handleAppService.selectCategorizeAll(keyword));
    }

    /**
     * 查询办事列表（分页）
     */
    @SaIgnore
    @GetMapping("/pageList/{categorizeId}")
    public TableDataInfo<CustomHandleAppVO> pageList(@NotNull(message = "分类不能为空") @PathVariable Long categorizeId,PageQuery pageQuery) {
        HandleAppDO dto = new HandleAppDO();
        dto.setHcId(categorizeId);
        dto.setStatus("0");
        return handleAppService.pageList(dto, pageQuery);
    }

    /**
     * 搜索-查询办事列表
     */
    @SaIgnore
    @GetMapping("/query/list")
    public R<List<HandleAppVO>> queryList(@NotBlank(message = "关键字不能为空") String keyword) {
        return R.ok(handleAppService.queryList(keyword));
    }
}
